package com.cy.zs.hp.common.exception;

import com.cy.zs.hp.common.jsonResult.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.NoHandlerFoundException;

import java.io.Serializable;

/**
 * 异常处理器
 */
@RestControllerAdvice
@Slf4j
public class HpExceptionHandler implements Serializable {
    private static final long serialVersionUID = 3084638994796179817L;

    /**
     * 处理自定义异常
     * @return
     */
    @ExceptionHandler(HpException.class)
    public JsonResult handleZSException(HpException e){
        log.error("e.message{}",e.getMessage());
        return  new JsonResult(e);
    }

    @ExceptionHandler(NoHandlerFoundException.class)
    public JsonResult handlerNoFoundException(Exception e) {
        log.error("e.message{}",e.getMessage());
        return  new JsonResult(e);
    }

    @ExceptionHandler(DuplicateKeyException.class)
    public JsonResult handleDuplicateKeyException(DuplicateKeyException e){
        log.error("e.message{}",e.getMessage());
        return  new JsonResult(e);
    }


    @ExceptionHandler(Exception.class)
    public JsonResult handleException(Exception e){
        log.error("e.message{}",e.getMessage());
        return  new JsonResult(e);
    }
}


